package com.wf.exception;

import com.wf.constant.MessageConstant;
import com.wf.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 *
 * @author mpk
 * @since 2024/8/19 15:25:16
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 处理业务异常
     *
     * @param ex
     * @return
     */
    @ExceptionHandler(ApartmentException.class)
    public Result errorByApartmentException(ApartmentException ex) {
        return Result.failure(ex.getMessage());
    }

    /**
     * 处理系统异常
     *
     * @param ex
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result errorByException(Exception ex) {
        log.error("系统异常", ex);
        return Result.failure(MessageConstant.SYSTEM_ERROR);
    }


}
